const app = getApp();
const util = require('../../../../../utils/util')
Component({
  lifetimes: {
    created() {
    },
    attached() {
    }
  },
  data: {
    isClose: "", 
    flag: false,
    types:[{id:0,name:'全部',checked:true},{id:1,name:'收入'},{id:2,name:'支出'}],
    type:'',
    //11.销售收入,12.进货奖励,13.服务收入,14.分红收入,15.其他收入,21.消费支出,22.提现支出,23.其他支出
    queryType:[{id:0,name:'全部',invisible:true,checked:true},{id:11,name:'销售收入',invisible:true},{id:12,name:'进货奖励',invisible:true},{id:13,name:'服务收入',invisible:true},{id:14,name:'分红收入',invisible:true},{id:15,name:'其他收入',invisible:true},{id:21,name:'消费支出',invisible:true},{id:22,name:'提现支出',invisible:true},{id:23,name:'其他支出',invisible:true}],
    currentType:{},
  },
  methods: {
    removeItem(item, index) {
      var _this = this
      del(item.id).then(res => {
        _this.goRight(index, 0);
        _this.accountlist.splice(index, 1);
      })
    },
    handleSwipe(e, index) {
      if (e.direction == "left") {
        this.goLeft(index);
      } else if (e.direction == "right") {
        this.goRight(index);
      }
    },
    //11.销售收入,12.进货奖励,13.服务收入,14.分红收入,15.其他收入,21.消费支出,22.提现支出,23.其他支出
    selectType(e){
      let _this = this
      this.data.type = e.target.dataset.item
      this.data.types.forEach(item => {
        if(item.id==e.target.dataset.item.id){
          let propertyName = "checked";
          item[propertyName] = true
        }else item.checked = false
      });
      if(e.target.dataset.item.id ==1){
        this.data.queryType.forEach(item => {
          let propertyName = "invisible";
          if(item.id==21||item.id==22||item.id==23){
            item[propertyName] = false
          }
          else item[propertyName] = true
        });
      }else if(e.target.dataset.item.id ==2){
        this.data.queryType.forEach(item => {
          let propertyName = "invisible";
          if(item.id==11||item.id==12||item.id==13||item.id==14||item.id==15){
            item[propertyName] = false
          }
          else  item[propertyName] = true
        });
      }else {
        this.data.queryType.forEach(item => {
          let propertyName = "invisible";
          item[propertyName] = true
      });
      }
      _this.setData({
        queryType:this.data.queryType,
        types:this.data.types,
        type:this.data.type,
      })
      if(e.target.dataset.item !=0)
      this.clearQuery()
    },
    //选择筛选类型
    selectTypeClick(e) {
      let _this = this
      this.data.currentType = e.target.dataset.item
      if(e.target.dataset.item.invisible==false){
        return
      }
      this.data.queryType.forEach(item => {
        if(item.id==e.target.dataset.item.id){
          let propertyName = "checked";
          item[propertyName] = true
        }else item.checked = false
      });
      _this.setData({
        queryType:this.data.queryType,
        currentType:this.data.currentType
      })
    },
    //清除上次选项
    clearQuery(){
      this.data.queryType.forEach(item => {
        if(item.invisible==false && item.checked==true){
         item.checked = false
         this.data.queryType[0].checked = true
        }
      });
      this.setData({
        queryType:this.data.queryType,
      })
    },

    submit() {
      this.hideFrame();
      // if(!util.isNull(this.data.type)){
      //   if(!util.isNull(this.data.currentType && this.data.currentType.id!=0)){
      //     this.triggerEvent("selectedInfo", this.data.currentType)
      //   }else if(!util.isNull(this.data.currentType && this.data.currentType.id == 0)){
      //     this.triggerEvent("selectedInfo", this.data.type)
      //   }
      // }else{
      //   this.triggerEvent("selectedInfo", this.data.type)
      // }
      if(util.isNull(this.data.type) && util.isNull(this.data.currentType)){
        this.triggerEvent("selectedInfo", {type:'',moreType:''})
      }else if(util.isNull(this.data.type)&& !util.isNull(this.data.currentType)){
        this.triggerEvent("selectedInfo", {type:'',moreType:this.data.currentType})
      }else if(!util.isNull(this.data.type)&& util.isNull(this.data.currentType)){
        this.triggerEvent("selectedInfo", {type:this.data.type,moreType:''})
      }else
      this.triggerEvent("selectedInfo", {type:this.data.type,moreType:this.data.currentType})
    },
    //显示底部弹窗
    showFrame(id, type) {
      this.data.flag = true
      this.setData({
        flag: this.data.flag
      })
    },
    //隐藏底部弹窗
    hideFrame() {
      this.data.flag = false,
        this.setData({
          flag: this.data.flag
        })
    },
    // nodes(){},
    /**
     * 处理滑动开始
     */
    // handleTouchStart(e) {
    //   this.data.startX = e.touches[0].pageX
    // },

    /**
     * 处理滑动
     */
    // handleTouchEnd(e) {
    //   let index = e.currentTarget.dataset.index;
    //   if (index == this.data.num) {
    //     this.hideDeleteButton(e)
    //     return
    //   }

    //   if (e.changedTouches[0].pageX < this.data.startX && e.changedTouches[0].pageX - this.data.startX <= -30 && index != this.data.num) {
    //     //左滑 
    //     this.showDeleteButton(e)
    //   } else if (e.changedTouches[0].pageX > this.data.startX && e.changedTouches[0].pageX - this.data.startX < 30 && index != this.data.num) {
    //     //右滑
    //     this.showDeleteButton(e)
    //   } else {
    //     this.hideDeleteButton(e)
    //   }
    // },
    /**
      * 显示删除按钮
      */
    // showDeleteButton(e) {
    //   let index = e.currentTarget.dataset.index;
    //   if (index!=this.data.moveIndex) {
    //     this.hideDeleteButton()
    //   }
    //   this.data.moveIndex = index
    //   this.setXmove(index, -65);
    // },


    /**
      * 隐藏删除按钮
      */
    // hideDeleteButton(e) {
    //   let index = e ? e.currentTarget.dataset.index : this.data.moveIndex;
    //   this.setXmove(index, 0);
    // },


    /**
     * 设置movable-view位移
     */
    // setXmove(index, xmove) {
    //   let { accountlist } = this.data;
    //   accountlist[index].xmove = xmove;
    //   this.setData({
    //     accountlist: accountlist
    //   })
    // },

    /**
      * 处理movable-view移动事件
      */
    // handleMovableChange(e) {
    //   if (e.detail.source === 'friction') {
    //     if (e.detail.x < -30) {
    //       this.showDeleteButton(e)
    //     } else {
    //       this.hideDeleteButton(e)
    //     }
    //   } else if (e.detail.source === 'out-of-bounds' && e.detail.x === 0) {
    //     this.hideDeleteButton(e)
    //   }
    // },

    // handleDelete(e) {
    //   const { id, index } = e.currentTarget.dataset;
    //   if (index == this.data.num) {
    //     wx.showToast({
    //       title: '已选择不能删除',
    //       icon: 'none'
    //     })
    //     return
    //   }
    //   if (index < this.data.num) {
    //     this.data.num -= 1
    //   }
    //   del(id).then(res => {
    //     this.data.accountlist.splice(index, 1)
    //     this.setData({
    //       num: this.data.num,
    //       accountlist: this.data.accountlist
    //     })
    //     wx.showToast({
    //       title: '删除成功',
    //       icon: 'success'
    //     })
    //   })
    // }


  }
})
